#ifndef UTILS_HPP
#define UTILS_HPP
#include "../3rdparty/canpp/src/private/SpinLock.hpp"
#include <random>
#include <string>
#include <format>
#include <thread>
using std::string;
using std::vformat;
using std::format_args;
using std::make_format_args;

inline int random_number(const int min, const int max) {
    std::random_device rd;
    std::mt19937 gen(rd());
    std::uniform_int_distribution<> dist(min, max);
    return dist(gen);
}

inline string configGenerate(const string &&filename, const bool console = false, const bool textfile = true) {
    const string console_config = console
                                      ? "appenders_config.appender_0.enable=true"
                                      : "appenders_config.appender_0.enable=false";
    const string textfile_config = textfile
                                       ? "appenders_config.appender_1.enable=true"
                                       : "appenders_config.appender_1.enable=false";
    string config = vformat(R"(
            #type
            appenders_config.appender_0.type=console
            {}
            appenders_config.appender_1.type=text_file
            {}
            #time_zone
            appenders_config.appender_0.time_zone=default local time
            appenders_config.appender_1.time_zone=default local time
            #log_level
            appenders_config.appender_0.levels=[debug,info,warning,error,fatal]
            appenders_config.appender_1.levels=[debug,info,warning,error,fatal]
            appenders_config.appender_1.file_name={}
            appenders_config.appender_1.max_file_size=10000000)",
                            format_args(make_format_args(
                                console_config, textfile_config,
                                filename)));
    return config;
}

#endif //UTILS_HPP
